version: '3.9'
networks:
  default:
services:
#  php:
#    hostname: "testapi"
#    domainname: testapi.local
#    image: yiisoftware/yii2-php:8.3-apache # yii2-php:8.3-fpm # yii2-php:8.3-apache
#    volumes:
#      - ~/.composer-docker/cache:/root/.composer/cache:delegated
#      - ./:/app:delegated
#      #- ./config/apache_conf:/etc/apache2/sites-enabled/
#    ports:
#      - '8204:80'
#      - '8205:8087'
#    depends_on:
#      - api-postgres
#      - api-postgres-test
#    #networks:
#    #  testyii2:
#    #    ipv4_address: 172.25.0.11

  api-php-fpm:
    build:
      context: docker
      dockerfile: development/php-fpm/Dockerfile
    environment:
      APP_ENV: dev
      APP_DEBUG: 1
      PHP_IDE_CONFIG: serverName=Frontend
    volumes:
      - .:/app

  api-php:
    hostname: testapi
    build:
      context: docker
      dockerfile: development/nginx/Dockerfile
    ports:
      - '8204:80'
      - '8205:8087'
    volumes:
      - .:/app
    depends_on:
      - api-php-fpm
      - api-postgres
      - api-postgres-test

  api-postgres:
    image: postgres:16.2-alpine
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
      PGDATA: "/var/lib/postgresql/data/pgdata"
    volumes:
      - vtestapi:/var/lib/postgresql/data
    #            - db-postgres:/var/lib/postgresql/data
    # net stop winnat // перезапуск службы, если бд не запускается (Windows)
    # docker-compose run --rm php composer install // обновление композера, установка расширений, работа с консолью
    ports:
      - "54337:5432"

  api-postgres-test:
    image: postgres:16.2-alpine
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
      PGDATA: "/var/lib/postgresql/data/pgdatatest"
    volumes:
      - vtestapi:/var/lib/postgresql/datatest
    ports:
      - "54338:5432"

volumes:
  vtestapi:
    external: true
